﻿@{
    ViewBag.Title = "Votes";
    Layout = null;
    var Model = ViewBag.Model;
    var PlaceHolder = ViewBag.PlaceHolder;
    var VoteNumbers = ViewBag.VoteNumbers;
    var VoteNumberId = ViewBag.VoteNumberId;
}
<link href="@Url.Content("~/Content/common.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/demos.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/jquery-weui.min.css")" rel="stylesheet" type="text/css" />

<script src="@Url.Content("~/Scripts/jquery-1.9.1.min.js")"></script>
<script src="@Url.Content("~/Scripts/fastclick.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.lazyload.js")"></script>
<script src="@Url.Content("~/Scripts/lhgdialog/lhgdialog.min.js")"></script>
<script src="@Url.Content("~/Scripts/common.js")"></script>
<!DOCTYPE html>
<html>
<head>
    <title>"童心 同乐"六一少儿艺术展演</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <style>
        body {background: url("@Url.Content("~/images/liu-bg_01.png")") no-repeat;background-size: cover; }
        .clckClass{background: rgb(4, 190, 2) !important;color: #fff !important;}
        .weui-btn{padding:0;}
        .weui-dialog__hd {padding:1.5rem 1rem;}
        .moren{display: block;background: #795dc3;width: 66%;text-align: center;color: #a8e9ff; height: 1.6rem;font-size: 72%; margin: 23% 17%;line-height: 1.6rem;border-radius: 3px;}
    </style>
</head>

<body>
    <!--轮播-->
    <div class="swiper-box">
        <div class="swiper-container">
            <!-- Additional required wrapper -->
            <div class="swiper-wrapper">
                <!-- Slides -->
                <div class="swiper-slide"><img src="@Url.Content("~/images/swiper-1.jpg")" /></div>
                <div class="swiper-slide"><img src="@Url.Content("~/images/swiper-2.jpg")" /></div>
                <div class="swiper-slide"><img src="@Url.Content("~/images/swiper-3.jpg")" /></div>
            </div>
            <!-- If we need pagination -->
            <div class="swiper-pagination"></div>
        </div>
    </div>


    <ul class="nav-box">
        <li><a class="moren clckClass" votenumberid="-1">全部</a></li>
        @if (VoteNumbers != null)
        {
            foreach (var voteNu in VoteNumbers)
            {
                <li><a class="moren" votenumberid="@voteNu.Id">@voteNu.Name</a></li>
            }
        }
    </ul>

    </script>

    <!--搜索-->
    @*@if (PlaceHolder != null && PlaceHolder != "")
        {
            <div class="search-box">
                <input class="search-tip fl" id="FestivalName" type="text" onkeydown="serkeydown(this,event)" placeholder=@PlaceHolder>
                <a class="search-btn fr" onclick="return submitSearch('FestivalName');">搜索</a>
            </div>
        }
        else
        {*@
    <div class="search-box">
        <input class="search-tip fl" id="FestivalName" type="text" onkeydown="serkeydown(this,event)" placeholder="请输入节目编号或名称">
        <a class="search-btn fr" onclick="return submitSearch('FestivalName');">搜索</a>
    </div>
    @*}*@
    <!--搜索滚动-->
    <div class="search-box" id="logo" style="padding-top:0;">
        <input class="search-tip fl" id="FestivalName1" type="text" onkeydown="serkeydown1(this,event)" placeholder="请输入节目编号或名称">
        <a class="search-btn fr" style="margin-top:0.3rem;" onclick="return submitSearch('FestivalName1');">搜索</a>
    </div>
    <!--搜索滚动-->
    <div class="footer-top">
        <img src="@Url.Content("~/images/footer-top.png")">
    </div>
    <!---->
    <div class="VoteTime">
        <span class="VoteTime-text"><a id="changCi" style="color:red;font-size:0.7rem;"></a>投票时间<span class="VoteTime-Start" style="padding-left:0.3rem;"></span></span><span class="VoteTime-text">~</span>
        <span class="VoteTime-text"><span class="VoteTime-End"></span>还剩余<a id="remainVotes" style="color:red;font-size:0.7rem;"></a>票</span>
    </div>
    <script>

        $(window).scroll(function () {
            var scrollTop = $(window).scrollTop();
            if (scrollTop < 380) {
                $("#logo").css({
                    'display': "none",
                });
            }
            if (scrollTop > 380) {
                $("#logo").css({
                    'display': "block",
                });
            }
        });
        /* 回到顶部 */
        $(function () {
            $(function () {
                $(window).scroll(function () {
                    /* 判断滚动条 距离页面顶部的距离 100可以自定义*/
                    if ($(window).scrollTop() > 600) {
                        $(".footer-top").fadeIn(200); /* 这里用.show()也可以 只是效果太丑 */
                    } else {
                        $(".footer-top").fadeOut(200);
                    }
                });
            });
            /* 给图片元素绑定 回到顶部的事件 */
            $(function () {
                $(".footer-top").on("click", function () {
                    $('body,html').animate({
                        scrollTop: 0
                    }, 500);
                    return false;
                });
            });
        });


    </script>
    <!--player选手列表-->
    <div class="player-box">
        <ul class="player" id="list">
            @if (Model != null)
            {
                foreach (var VotesShows in Model)
                {
                    <li>
                        <div class=" player-list fl">
                            <div class="p-img-box">
                                <a href="@Url.Action("FestivalDetail", "Home", new { VoteShowId = VotesShows.Id, canVoteType = VotesShows.canVoteType })">
                                    <img class="lazy list-p-icon" src="@VotesShows.ImgUrl.Replace("_source","_s")">
                                </a>

                            </div>
                            <div class="r-p-text">
                                @*<img  src="@Url.Content("~/images/p-number.png")">*@
                                <div class="p-num">
                                    <span id="@VotesShows.Id-head">@VotesShows.Identify</span>
                                </div>

                            </div>
                            <div class="p-text-box">
                                <div class="p-text p-text-text fl">
                                    <h4>@VotesShows.Name</h4>
                                    <span>票数：</span><span id="@VotesShows.Id-bottom">@VotesShows.VoteNum</span>
                                </div>
                                @if (VotesShows.canVoteType == 1)
                                {
                                    <div class="p-text dianji fr">
                                        <a id=@VotesShows.Id onclick="toupiao(this)">投票</a>
                                    </div>
                                }
                                else if (VotesShows.canVoteType == 0)
                                {
                                    <div class="p-text fr">
                                        <a class="weui-btn weui-btn_disabled weui-btn_default" style="padding: 0;pointer-events:none;  color:#afafaf;  cursor:default" id=@VotesShows.Id>已投</a>
                                    </div>
                                }
                                else if (VotesShows.canVoteType == 2)
                                {
                                    <div class="p-text fr">
                                        <a class="weui-btn weui-btn_disabled weui-btn_default" style="padding: 0;pointer-events:none;  color:#afafaf;  cursor:default" id=@VotesShows.Id>票数用完</a>
                                    </div>
                                }
                                else
                                {
                                    <div class="p-text fr">
                                        <a class="weui-btn weui-btn_disabled weui-btn_default" style="padding: 0;pointer-events:none;  color:#afafaf;  cursor:default" id=@VotesShows.Id>场次过期</a>
                                    </div>
                                }
                            </div>
                        </div>
                    </li>
                }
            }

        </ul>
    </div>



    <!--footer菜单-->
    <ul class="footer-menu">
        <li><a href="#">参赛节目</a></li>
        <li><a href="#" onclick="hehe()">赛事规则</a></li>
        <li><a href="http://m.gxanr.com">爱农人商城</a></li>
    </ul>
    <script>
        $(function () {
            FastClick.attach(document.body);
        });
    </script>
    <script src="@Url.Content("~/Scripts/jquery-weui.min.js")"></script>
    <script src="@Url.Content("~/Scripts/swiper.min.js")"></script>
    <script>
        $(".swiper-container").swiper({
            loop: true,
            autoplay: 3000
        });
    </script>
    <!--弹框-->
    <script>
        var pageIndex = 1;
        $(document).ready(function () {
            VoteSwitch();
            $(window).scroll(function () {
                //$(window).scrollTop()这个方法是当前滚动条滚动的距离
                //$(window).height()获取当前窗体的高度
                //$(document).height()获取当前文档的高度
                var bot = 50; //bot是底部距离的高度
                if ((bot + $(window).scrollTop()) >= ($(document).height() - $(window).height())) {
                    //当底部基本距离+滚动的高度〉=文档的高度-窗体的高度时；
                    //我们需要去异步加载数据了
                    pageIndex++;
                    var VoteNumberIdTemp = $(".clckClass").attr("votenumberid");
                    $.getJSON("/Home/PageList", { PageIndex: pageIndex, VoteNumberId: VoteNumberIdTemp }, function (data) {
                        var html = "";
                        var htmlResult = "";
                        var htmlTemp = "";
                        var loadSting = "";
                        var htmlHead = "<ul class='player' id='list'>";
                        var htmlEnd = "</ul>";
                        $.each(data, function (i, item) {
                            if (item.canVoteType == 1) {
                                htmlTemp = "<div class='p-text fr'><a id=" + item.Id + " onclick='toupiao(this)'>投票</a></div>"

                            }
                            else if (item.canVoteType == 0) {
                                htmlTemp = "<div class='p-text fr' ><a class='weui-btn weui-btn_disabled weui-btn_default' style='padding:0;" +
                                         "pointer-events:none;  color:#afafaf;  cursor:default;    margin-top: 0.5rem;'" +
                                          item.Id + ">已投</a></div>";
                            }
                            else if (item.canVoteType == 2) {
                                htmlTemp = "<div class='p-text fr' ><a class='weui-btn weui-btn_disabled weui-btn_default' " +
                                         "style='padding: 0;pointer-events:none;  color:#afafaf;    margin-top: 0.5rem;  cursor:default' id=" + item.Id +
                                         ">票数用完</a></div>";
                            }
                            else {
                                htmlTemp = "<div class='p-text fr' ><a class='weui-btn weui-btn_disabled weui-btn_default' " +
                                         "style='padding: 0;pointer-events:none;  color:#afafaf;    margin-top: 0.5rem;  cursor:default' id=" + item.Id +
                                         ">场次过期</a></div>";
                            }
                            html = "<li><div class=' player-list fl'><div class='p-img-box'>" +
                                  "<a href=/Home/FestivalDetail?VoteShowId=" + item.Id + "&&canVoteType=" + item.canVoteType + ">" +
                                  "<img class='lazy list-p-icon' src='" + item.ImgUrl.replace("_source", "_s") + "'></a></div>" +
                                  "<div class='r-p-text'><div class='p-num'><span id='" +
                                    item.Id + "-head'>" + item.Identify + "</span></div></div>" +
                            "<div class='p-text-box'><div class='p-text p-text-text fl'>" +
                            "<h4>" + item.Name + "</h4>" +
                            "<span>票数：</span><span id='" + item.Id + "-bottom'>" + item.VoteNum + "</span></div>" + htmlTemp;
                            htmlResult = htmlResult + html;
                        })
                        $(".player-box").append(htmlHead + htmlResult + htmlEnd);
                    })
                }
            });
        })
        function hehe() {
            confirmHtml("呵呵", 0, false);
        }
        //弹框 LeaveVoteNum 0为跳转到微商城 1是不跳转直接取消
        function confirmHtml(text, LeaveVoteNum, flage) {
            var htmlDemp = '';
            var htmlBody = '';
            //单选、多选样式判断
            if (!flage) {
                htmlDemp = ' <div class="close ding-hui  fl" style="margin-left:0.5rem;background:#795dc3;color:#fff;" onclick="CancelConfirm(this)">'
                            + ' 取消'
                            + '</div>';
                htmlBody = '<div class="footer-tan">'
                            + ' <div class="close ding-hui fl" style="color:#795dc3;"onclick="SkipConfirm(this)" LeaveVoteNum=' + LeaveVoteNum + '>'
                            + ' 确定'
                            + '</div>' + htmlDemp
                           + '</div>';
            }
            else {
                htmlBody = '<div class="footer-tan">'
                            + ' <div class="close ding-hui fl" style="color:#fff;margin-left:27%;background:#795dc3;"onclick="SkipConfirm(this)" LeaveVoteNum=' + LeaveVoteNum + '>'
                            + ' 确定'
                            + '</div>' + htmlDemp
                           + '</div>';
            }
            var html = '<div class="tan">'
                  + '<div class="tan-bg">'
                      + '<div class="tan-box">'
                         + '<h3>'
                            + '<a  onclick="CancelConfirm(this)" LeaveVoteNum=' + LeaveVoteNum + '>'
                                + text
                            + '</a>'
                         + '</h3>' + htmlBody
                      + '</div>'
                  + ' </div>'
                 + ' </div> ';
            $('body').append(html);
            $(".tan").show();
        }
        //弹框,确认跳转到微商城
        function SkipConfirm(obj) {
            $(".tan").hide();
            var LeaveVoteNum = $(obj).attr("LeaveVoteNum");
            if (LeaveVoteNum == 0) {
                window.location.href = "http://m.gxanr.com";
            }
        }
        //取消
        function CancelConfirm(obj) {
            $(".tan").hide();
        }

        //场次切换
        function VoteSwitch() {
            $('.nav-box li a').bind('click', function () {
                var loading = TipsBox("", "loading", 60, true);
                var votenumberId = $(this).attr("votenumberid");
                var ss = $(this).text();
                $.post("/Home/VoteSwitch", { VoteNumberId: votenumberId }, function (data) {
                    if (loading != null) {
                        loading.close();
                    }
                    if (votenumberId == -1) {
                        $(".VoteTime").css({ display: "none" });
                    }
                    else {
                        $(".VoteTime-Start").html(data.StartTime);
                        $(".VoteTime-End").html(data.EndTime);
                        $("#changCi").html(ss);
                        $("#remainVotes").text(data.RemainVotes);
                        $(".VoteTime").show();
                    }
                    var html = "";
                    var htmlResult = "";
                    var htmlTemp = "";
                    var loadSting = "";
                    var htmlHead = "<ul class='player' id='list'>";
                    var htmlEnd = "</ul>";
                    $.each(data.VoteModel, function (i, item) {
                        if (item.canVoteType == 1) {
                            htmlTemp = "<div class='p-text fr'><a id=" + item.Id + " onclick='toupiao(this)'>投票</a></div>"

                        }
                        else if (item.canVoteType == 0) {
                            htmlTemp = "<div class='p-text fr' ><a class='weui-btn weui-btn_disabled weui-btn_default' style='padding:0;" +
                                     "pointer-events:none;  color:#afafaf;  cursor:default;    margin-top: 0.5rem;'" +
                                      item.Id + ">已投</a></div>";
                        }
                        else if (item.canVoteType == 2) {
                            htmlTemp = "<div class='p-text fr' ><a class='weui-btn weui-btn_disabled weui-btn_default' " +
                                     "style='padding: 0;pointer-events:none;  color:#afafaf;    margin-top: 0.5rem;  cursor:default' id=" + item.Id +
                                     ">票数用完</a></div>";
                        }
                        else {
                            htmlTemp = "<div class='p-text fr' ><a class='weui-btn weui-btn_disabled weui-btn_default' " +
                                     "style='padding: 0;pointer-events:none;  color:#afafaf;    margin-top: 0.5rem;  cursor:default' id=" + item.Id +
                                     ">场次过期</a></div>";
                        }
                        html = "<li><div class=' player-list fl'><div class='p-img-box'>" +
                              "<a href=/Home/FestivalDetail?VoteShowId=" + item.Id + "&&canVoteType=" + item.canVoteType + ">" +
                              "<img class='lazy list-p-icon' src='" + item.ImgUrl.replace("_source", "_s") + "'></a></div>" +
                              "<div class='r-p-text'><div class='p-num'><span id='" +
                                item.Id + "-head'>" + item.Identify + "</span></div></div>" +
                        "<div class='p-text-box'><div class='p-text p-text-text fl'>" +
                        "<h4>" + item.Name + "</h4>" +
                        "<span>票数：</span><span id='" + item.Id + "-bottom'>" + item.VoteNum + "</span></div>" + htmlTemp;
                        htmlResult = htmlResult + html;
                    })
                    $(".player-box").html(htmlHead + htmlResult + htmlEnd);
                })
            })
        }

        //懒加载
        $(function () {
            $("img.lazy").lazyload({ effect: "fadeIn" });
        });

        function VoteByUser() {

        }
        //投票
        function toupiao(obj) {
            $(".weui-dialog__btn").click(function () {
                var LeaveVoteNum = $(obj).attr("LeaveVoteNum");
                $(".weui-mask,.weui-dialog").hide();
                if (LeaveVoteNum == 0) {
                    window.location.href = "m.gxanr.com";
                }
            })

            var showIds = $(obj).attr("id");
            var ancestors = $(obj).parent().parent().parent();
            $.ajax({
                type: "post",
                url: '@Url.Action("VoteByUser","Home")',
                data: { showId: showIds },
                async: false,
                success: function (result) {
                    if (isNaN(result.returnUrl)) {
                        window.location.href = result.returnUrl; //重定向
                    } else {
                        if (result.VoteNum == 0) {
                            confirmHtml("今天已经投过了这个节目", 1, false);
                        }
                        else if (result.VoteNum == -2) {

                            //投票已经用完
                            confirmHtml("这个场次的投票已经用完,", 1, false);
                        }
                        else {
                            //投票成功
                            //$(this).html("已投");
                            ancestors.find("#" + showIds + "-head").text(result.VoteNum);
                            ancestors.find("#" + showIds + "-bottom").text(result.VoteNum);
                            ancestors.find("#" + showIds).addClass("weui-btn weui-btn_disabled weui-btn_default");
                            ancestors.find("#" + showIds).removeAttr("onclick");
                            if (result.result != null) {
                                var Message = "第一次投票，赠送" + result.result.Body + "优惠券";
                                confirmHtml(Message, 1, false);
                            }
                            if (result.LeaveVoteNum == 0) {
                                confirmHtml("这个场次的投票已经用完，您可以前往爱农人商城使用您的优惠券", 0, false);
                                ancestors.find("#" + showIds).html("票数用完");
                                return;
                            }
                            ancestors.find("#" + showIds).html("已投");
                            $("#remainVotes").test(result.LeaveVoteNum);
                        }
                    }
                }
            });
        }

        //搜索
        function submitSearch(FestivalName) {
            var VoteNumberId = $(".clckClass").attr("votenumberid");
            var FestNameTemp = document.getElementById(FestivalName).value;
            if (FestNameTemp == "") {
                confirmHtml("请输入节目编号或名称", 1, true);
            }
            if (FestNameTemp != null) {
                var loading = TipsBox("", "loading", 60, true);
                $.post("/Home/SearchFestival", { FestName: FestNameTemp, VoteNumberId: VoteNumberId }, function (data) {
                    if (loading != null) {
                        loading.close();
                    }
                    var html = "";
                    var htmlResult = "";
                    var htmlTemp = "";
                    var loadSting = "";
                    var htmlHead = "<ul class='player' id='list'>";
                    var htmlEnd = "</ul>";
                    $.each(data, function (i, item) {
                        if (item.canVoteType == 1) {
                            htmlTemp = "<div class='p-text dianji fr'><a id=" + item.Id + " onclick='toupiao(this)'>投票</a></div>"

                        }
                        else if (item.canVoteType == 0) {
                            htmlTemp = "<div class='p-text fr' ><a class='weui-btn weui-btn_disabled weui-btn_default' style='padding:0;" +
                                        "pointer-events:none;margin-top: 0.5rem;  color:#afafaf;  cursor:default'" +
                                        item.Id + ">已投</a></div>";
                        }
                        else if (item.canVoteType == 2) {
                            htmlTemp = "<div class='p-text fr' ><a class='weui-btn weui-btn_disabled weui-btn_default' " +
                                        "style='padding: 0;pointer-events:none;  color:#afafaf; margin-top: 0.5rem; cursor:default' id=" + item.Id +
                                        ">票数用完</a></div>";
                        }
                        else {
                            htmlTemp = "<div class='p-text fr' ><a class='weui-btn weui-btn_disabled weui-btn_default' " +
                                        "style='padding: 0;pointer-events:none;  color:#afafaf; margin-top: 0.5rem; cursor:default' id=" + item.Id +
                                        ">场次过期</a></div>";
                        }
                        html = "<li><div class=' player-list fl'><div class='p-img-box'>" +
                               "<a href=/Home/FestivalDetail?VoteShowId=" + item.Id + "&&canVoteType=" + item.canVoteType + ">" +
                                "<img class='lazy list-p-icon' src='" + item.ImgUrl.replace("_source", "_s") + "'></a></div>" +
                                "<div class='r-p-text'><div class='p-num'><span id='" +
                                item.Id + "-head'>" + item.Identify + "</span></div></div>" +
                                "<div class='p-text-box'><div class='p-text p-text-text fl'>" +
                                "<h4>" + item.Name + "</h4>" +
                                "<span>票数：</span><span id='" + item.Id + "-bottom'>" + item.VoteNum + "</span></div>" + htmlTemp;
                        htmlResult = htmlResult + html;
                    })
                    if (htmlResult != "") {
                        $(".player-box").html(htmlHead + htmlResult + htmlEnd);
                    }
                    else {
                        $(".player-box").html("<p style='text-align: center !important;'>没有找到该项节目...</p>");
                    }
                })
            }
        }
        //回车搜索
        function serkeydown(a, e) {
            var ev = document.all ? window.event : e;
            if (ev.keyCode == 13) {
                return submitSearch('FestivalName');
            }
        }
        function serkeydown1(a, e) {
            var ev = document.all ? window.event : e;
            if (ev.keyCode == 13) {
                return submitSearch('FestivalName1');
            }
        }
        $(".nav-box li a").bind("click", function () {
            $(".clckClass").removeClass("clckClass");
            $(this).addClass("clckClass");
        });
        $(document).ready(function () {
            $(".moren").click(function () {
                $(".VoteTime-text").show();
            });
        });

    </script>


</body>
</html>
